package com.ruoyi.zhgd.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.zhgd.domain.NAsphaltMatch;
import com.ruoyi.zhgd.domain.vo.*;
import com.ruoyi.zhgd.mapper.NAsphaltReportMatchMapper;
import com.ruoyi.zhgd.service.*;

import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 全天生产数据业务接口实现
 *
 * @author tll
 * @date 2023-10-12
 */
@RequiredArgsConstructor
@Service
@DS("sjcj")
public class NAsphaltReportMatchServiceImpl implements NAsphaltReportMatchService {

    private final NAsphaltReportMatchMapper baseMapper;

    private final INAsphaltMatchService inAsphaltMatchService;

    /**
     * 获取生产配比数据报表
     * @param params
     * @return
     */
    @Override
    public NAsphaltReportMatchVo info(Map<String, Object> params) {
        // 获取拌合楼编号、配方编号
        String stationCode = null == params.get("stationCode") ? null : params.get("stationCode").toString();
        String matchCode = null == params.get("matchCode") ? null : params.get("matchCode").toString();
        if (ObjectUtils.isEmpty(stationCode) || ObjectUtils.isEmpty(matchCode)) {
            throw new ServiceException("拌合楼、配方不可为空");
        }

        // 获取配方信息
        NAsphaltMatch match = inAsphaltMatchService.getByCode(matchCode);

        // 获取产量信息
        List<NAsphaltOutputCountVo> outputCountList = baseMapper.getOutputCountList(params);

        //获取产量分析
        NAsphaltOutputAnalysisVo outputAnalysis = baseMapper.getOutputAnalysis(params);
        if (ObjectUtils.isNotEmpty(outputAnalysis)) {
            outputAnalysis.count();
        }

        // 获取生产数据
        List<NAsphaltProduceMatchVo> produceDataList = baseMapper.getProduceDataList(params);

        // 获取温度分布图
        List<NAsphaltTempDistVo> tempDistList = baseMapper.getTempDistList(params);

        // 获取油石比分布图
        List<NAsphaltRatioDistVo> ratioDistList = baseMapper.getRatioDistList(params);

        // 返回结果
        NAsphaltReportMatchVo vo = new NAsphaltReportMatchVo();
        vo.setMatch(match);
        vo.setOutputCountList(outputCountList);
        vo.setOutputAnalysis(outputAnalysis);
        vo.setProduceDataList(produceDataList);
        vo.setRatioDistList(ratioDistList);
        vo.setTempDistList(tempDistList);

        return vo;
    }
}
